package com.yeyks.app.controller.base.config;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.yeyks.app.annotation.UnUpdateCheck;
import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.common.exception.ServiceException;
import com.yeyks.commonReference.service.config.ConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author fuchangshuai
 * @date 2019/3/26 4:27 PM
 */
@Api(tags = "配置")
@Slf4j
@RestController
@RequestMapping(value = "/app/config")
public class ConfigController {

    @Autowired
    private ConfigService configService;

    /**
     * 获取版本信息
     *
     * @return
     */
    @ApiOperation(value = "获取动态配置内容:v3.5")
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    @UnUpdateCheck
    public AjaxResponseBody<String> systemVersion(String key) {
        String value = configService.getValue(key);
        if (StrUtil.isBlank(value)) {
            throw new ServiceException("配置不存在");
        }
        return AjaxResponseBody.success(value);
    }

}
